package com.ecarx.library_base.scoket.model;

import com.ecarx.library_base.base_util.GsonUtils;
import com.google.gson.annotations.SerializedName;

public class SocketResponse {
    @SerializedName("msgid")
    public int msgId;
    public long seq;
    public int code;
    public String version;
    public String errorMsg;
    public Object data;

    public SocketResponse() {
    }

    public SocketResponse(int msgId, long seq, int code, String version, String errorMsg, Object data) {
        this.msgId = msgId;
        this.seq = seq;
        this.code = code;
        this.version = version;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public int getMsgId() {
        return msgId;
    }

    public long getSeq() {
        return seq;
    }

    public int getCode() {
        return code;
    }

    public String getVersion() {
        return version;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public Object getData() {
        return data;
    }

    public <T> T dataToJsonObj(Class<T> tClass) {
        if (data == null) {
            return null;
        }
        return GsonUtils.fromJson(data.toString(), tClass);
    }

    @Override
    public String toString() {
        return "SocketMsg{" +
                "msgId=" + msgId +
                ", seq=" + seq +
                ", code=" + code +
                ", version='" + version + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", data=" + data +
                '}';
    }
}
